package com.tju.ocean_ecology_website.service.impl;

import com.tju.ocean_ecology_website.entity.ActivityDetail;
import com.tju.ocean_ecology_website.dao.ActivityDetailDao;
import com.tju.ocean_ecology_website.service.ActivityDetailService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 活动详情表(ActivityDetail)表服务实现类
 *
 * @author shaolong
 * @since 2025-04-29 19:18:48
 */
@Service("activityDetailService")
public class ActivityDetailServiceImpl implements ActivityDetailService {
    @Resource
    private ActivityDetailDao activityDetailDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public ActivityDetail queryById(Long id) {
        return this.activityDetailDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param activityDetail 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<ActivityDetail> queryByPage(ActivityDetail activityDetail, PageRequest pageRequest) {
        long total = this.activityDetailDao.count(activityDetail);
        return new PageImpl<>(this.activityDetailDao.queryAllByLimit(activityDetail, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param activityDetail 实例对象
     * @return 实例对象
     */
    @Override
    public ActivityDetail insert(ActivityDetail activityDetail) {
        this.activityDetailDao.insert(activityDetail);
        return activityDetail;
    }

    /**
     * 修改数据
     *
     * @param activityDetail 实例对象
     * @return 实例对象
     */
    @Override
    public ActivityDetail update(ActivityDetail activityDetail) {
        this.activityDetailDao.update(activityDetail);
        return this.queryById(activityDetail.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Long id) {
        return this.activityDetailDao.deleteById(id) > 0;
    }
}
